#!/usr/bin/env python
import struct

LOWERBASE = map(ord, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')

fo = open('ks.table', 'w')
data = []
for c1 in range(0xa1, 0xfe+1):
	for c2 in range(0xa1, 0xfe+1):
		try:
			v = (chr(c1)+chr(c2)).decode('euc-kr')
			data.append(struct.pack('<H', ord(v)))
		except:
			data.append('\x00\x00')
for c1 in range(0x81, 0xa0+1):
	for c2 in LOWERBASE + range(0x81, 0xfe+1):
		try:
			v = (chr(c1)+chr(c2)).decode('cp949')
			data.append(struct.pack('<H', ord(v)))
		except:
			data.append('\x00\x00')
for c1 in range(0xa1, 0xc6+1):
	for c2 in LOWERBASE + range(0x81, 0xa0+1):
		try:
			v = (chr(c1)+chr(c2)).decode('cp949')
			data.append(struct.pack('<H', ord(v)))
		except:
			data.append('\x00\x00')
fo.write(struct.pack('<LL', 1, len(data)*2))
fo.write(''.join(data))

data = []
for c in range(0, 0x10000):
	try:
		v = unichr(c).encode('cp949')
		if len(v) == 1:
			data.append('\x00'+v)
		else:
			data.append(v)
	except:
		data.append('\x00\x00')
fo.write(struct.pack('<LL', 2, len(data)*2))
fo.write(''.join(data))

